package com.gency.subscribe.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.gency.subscribe.model.system.CompanyPro;
import com.gency.subscribe.model.system.CompanyProperty;
import com.gency.subscribe.model.system.CompanySupplement;
import com.gency.subscribe.model.system.OrderBase;
import com.gency.subscribe.model.system.PageBean;
import com.gency.subscribe.model.system.UserReg;
import com.gency.subscribe.service.system.ICompanyProService;
import com.gency.subscribe.service.system.ICompanyPropertyService;
import com.gency.subscribe.service.system.ICompanySupplementService;
import com.gency.subscribe.service.system.IOrderBaseService;
import com.gency.subscribe.service.system.IUserCompanyService;
import com.gency.subscribe.service.system.IUserRegService;

@Controller
@RequestMapping("/userReg")
public class UserRegController {
	
	@Autowired
	IUserRegService userRegService;
	@Autowired
	IOrderBaseService orderBaseService;
	@Autowired
	IUserCompanyService userCompanyService;
	@Autowired
	ICompanySupplementService  companySupplementService;
	@Autowired
	ICompanyPropertyService companyPropertyService;
	@Autowired
	ICompanyProService companyProService;
	
	@GetMapping("/list")
	public ModelAndView list(PageBean pb,ModelAndView mv,String company_name,String phone,Integer flage){
		Page<UserReg> page = new Page<UserReg>(pb.getCurPage(),pb.getPageSize());
		List<UserReg> list = userRegService.vipList(page,company_name,phone,flage);
		pb.setAllRow(page.getTotal());
		pb.setCurPage(page.getCurrent());
		pb.setTotalPage(page.getPages());
		pb.setNextPage(page.getOffset());
		pb.setBeforPage(page.getOffsetCurrent());
		pb.setPageSize(10);
		pb.setStartRow(1);
		mv.addObject("pagebean",pb);
		mv.addObject("viplist", list);
		mv.setViewName("vip/list");
		return mv;
	}
	
	
	@GetMapping(value="/update")
	public ModelAndView update(long order_id,Integer type,ModelAndView mv){
		mv.setViewName("redirec:list");
		OrderBase base = new OrderBase();
		base.setId(order_id);
		base.setFlag_rebate(type);
		orderBaseService.updateById(base);
		return mv;
	}
		
	@GetMapping(value="/detail")
	public ModelAndView detail(long user_id,long order_id,long comp_id,ModelAndView mv){
		mv.addObject("user_info", userRegService.selectById(user_id));
		mv.addObject("order_info", orderBaseService.selectById(order_id));
		mv.addObject("com_info", userCompanyService.selectById(comp_id));
		EntityWrapper<CompanySupplement> entityWrapper = new EntityWrapper<>();
		entityWrapper.eq("company_id", comp_id);
		CompanySupplement companySupplement = companySupplementService.selectOne(entityWrapper);
		mv.addObject("com_supper_info",companySupplement);
		if(null != companySupplement){
			EntityWrapper<CompanyProperty> entityWrapper2 = new EntityWrapper<>();
			entityWrapper2.eq("support_id", companySupplement.getId());
			mv.addObject("companyProperty", companyPropertyService.selectList(entityWrapper2));
			
			EntityWrapper<CompanyPro> entityWrapper3 = new EntityWrapper<>();
			entityWrapper2.eq("support_id", companySupplement.getId());
			mv.addObject("companyPros", companyProService.selectList(entityWrapper3));
		}
		mv.setViewName("redirec:list");
		
		return mv;
	}
	
}
